package com.example.aop_.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class TimeAspect {
    @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        //记录开始时间
        long beignTime=System.currentTimeMillis();
        //启动方法
        Object proceed = pjp.proceed();
        //记录结束时间
        long endTime=System.currentTimeMillis();
        log.info(pjp.getSignature()+"方法耗时:{}ms",endTime-beignTime);
        return proceed;
    }

}

